#include <iostream>
#include <cmath>
using namespace std;
int main()
{
	string str;
	while(cin>>str)
	{
		int lenth=str.length();
		int index=lenth-1;
		int jishu=0;
		int ans=0;
		while(index>1)
		{
			int num=0;
			if(str[index]>='0'&&str[index]<='9')
			{
				num=str[index]-'0';
			}
			else
			{
				num=str[index]-'A'+10;
			}
			num=num*pow(16,jishu);
			ans+=num;
			index--;
			jishu++;
		}
		cout<<ans<<endl;
	}
	return 0;
} 
